<!--商品组
- 1. 商品上拉请求
-->
<template>
  <view class="group-list">
    <slot></slot>
  </view>
</template>
<script>
export default {
  components:{
  },
  props:{
    requestData:{
      type: Function,
      required: true
    },
    paramsData:{
      type: Object,
      default: ()=>{}
    },
    limit:{
      type: Number,
      default: 10
    },
    page:{
      type: Number,
      default: 0
    },
    total:{
      type: Number,
      default: 0
    }
  },
  data(){
    return {
      offset: 0,
      isShowNoMore:false,
    }
  },
  created(){
    // this.handleRequestData(true);
  },

  watch:{
    page(){
      this.handleRequestData();
    }
  },
  methods:{
    //请求数据
    async handleRequestData(initial=false){
      try {
        if (Math.ceil(this.total / this.limit) < this.page && !initial) {
          throw '没有更多商品了';
          return ;
        }
        const result = await this.requestData({
          limit: this.limit,
          page: this.page,
          ...this.paramsData,
        });
        this.$emit('success', result);
        return Promise.resolve(result)
      } catch (error) {
        this.$emit('error', error);
        return Promise.reject(error)
      }
    },
    // 获取offset
    getPageOffset(current){
      return (current - 1) * this.limit;
    },

  }
}
</script>
<style lang="scss">
.group-list{

}
</style>
